<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/28
  Time: 14:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head>
  <base href="${pageContext.request.contextPath}/">
  <title>$Title$</title>
  <style>
    table tr:nth-child(odd){
      background: darkgray;
    }
    a{
      text-decoration: none;
    }
  </style>
  <script src="jq/jquery.js"></script>
</head>
<body>
<h1 align="center">新能源汽车动力电池信息</h1>
<table border="1px" align="center">
  <tr style="background: lightgray" align="center">
    <th>编号</th>
    <th>车型</th>
    <th>所属城市</th>
    <th>使用单位</th>
    <th>压差报警值</th>
    <th>报警时间</th>
    <th>操作</th>
  </tr>
  <c:forEach var="power" items="${sessionScope.list}">
    <tr align="center">
      <td><a href="PowerBatterySelect?id=${power.id}">${power.id}</a></td>
      <td>${power.carName}</td>
      <td>${power.cityName}</td>
      <td>${power.userName}</td>
      <td>${power.pressureValue}</td>
      <td>${power.time}</td>
      <td><a href="javascript:void(0)" onclick="remove('${power.id}')">删除</a></td>
    </tr>
  </c:forEach>
</table>
  </body>
  <script>
    function remove(id) {
      if (confirm("确认删除吗？")) {
        $.getJSON(
                "PowerBatteryDelete",
                {id:id},
                function (data) {
                  if(data) {
                    alert("删除成功");
                    location.href = 'PowerBatteryList'
                  }else{
                    alert("删除失败")
                  }
                }
        )
      }
    }
  </script>
</html>
